package org.itboys.core.controller.front;



import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.admin.service.lasted.SundayUploadService;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.core.util.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;


/**
 * 作者：zzq
 * 日期：2017年9月4日
 * 描述：文件上传
 */
@Controller
@RequestMapping("/sunday/mobile/upload")
@Api(value = "common",description = "文件")
public class SundayFrontUploadController extends BaseController {
	@Autowired
	private SundayUploadService uploadService;

	/**
	 * 单个文件上传
	 * @param request
	 * @param response
	 * @param file
	 */
	@RequestMapping(value = "/uploadSingle",method= RequestMethod.POST)
	@ApiOperation(value = "单个文件上传。图片上传，大小超过1MB,将会被压缩")
	public void uploadSingle(
			HttpServletRequest request,
			HttpServletResponse response,
			@ApiParam(value = "单个文件流") @RequestParam(value="file",required=true)MultipartFile file
	)throws IOException {
		Map<String,String> result = uploadService.uploadSingle(file);
		ResponseMessage.success(result);
	}

	/**
	 * 多个文件上传
	 * @param request
	 * @param response
	 * @param files
	 */
	@RequestMapping(value = "/uploadMulti",method= RequestMethod.POST)
	public void uploadMulti(
			HttpServletRequest request,
			HttpServletResponse response,
			@ApiParam(value = "多个文件流。数组")  @RequestParam(value="files",required=true)MultipartFile[] files
	)throws IOException {
		List<Map<String,String>> result = uploadService.uploadMulti(files);
		ResponseMessage.success(result);
	}

}
